package day06;

import java.util.Random;
import java.util.Scanner;

public class HomeworkDay06 {
    public static void main(String[] args) {
        Random rand = new Random();
        Scanner scan = new Scanner(System.in);
        /*
        完成猜数字小游戏
        要求：使用while(true)自造死循环实现
         */
        /*

        int num = rand.nextInt(100);
        System.out.println(num);
        System.out.println("请输入猜测数字");
        int guess=scan.nextInt();
        while(true){
            if(guess==num){
                break;
            }
            if (guess>num){
                System.out.println("猜大了");
            }
            if(guess<num){
                System.out.println("猜小了");
            }
            System.out.println("请输入猜测数字");
            guess=scan.nextInt();
        }
        System.out.println("猜对啦！");

         */
        /**
         * 需求:<<主持人大赛>>有N位评委给选手打分
         * 选手的最终得分为:去掉最高分和最低分之后的N-2位评委的平均分
         * 要求:使用方法实现
         */
        System.out.println(calAvg(getScore(6)));

    }
    //评委打分方法
    public static double[] getScore(int n){
        Scanner scan = new Scanner(System.in);
        double[] score =  new double[n];
        for (int i = 0; i < score.length; i++){
            System.out.println("请第"+(i+1)+"位评委打分");
            score[i] = scan.nextDouble();
        }
        return score;
    }
    //平均分计算方法
    public static double calAvg(double[] scores){
        double avg;
        double sum = 0;
        double max  =scores[0];
        double min  =scores[0];
        for (int i=0;i<scores.length;i++){
            sum+=scores[i];
            if (max<scores[i]){
                max = scores[i];
            }
            if (min>scores[i]){
                min = scores[i];
            }
        }
        avg = (sum-max-min)/(scores.length-2);
        return avg;
    }
}
